package org.zecontech.extraplus.entity;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.AgeableMob;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.animal.Animal;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;
import org.zecontech.extraplus.init.ModEntities;

public class Nailong extends Kelong {

    public Nailong(EntityType<? extends Animal> p_27557_, Level p_27558_) {
        super(p_27557_, p_27558_);
    }

    /**
     * 实体的幼体
     * @param serverLevel 服务端世界
     * @param ageableMob 可生长的实体
     * @return 新的幼年实体
     */
    @Override
    public @Nullable AgeableMob getBreedOffspring(ServerLevel serverLevel, AgeableMob ageableMob) {
        return ModEntities.NAILONG.get().create(serverLevel, EntitySpawnReason.SPAWNER);
    }

    /**
     * 右键交互实体
     * @param p_401345_ 玩家
     * @param p_401405_ 玩家的手
     * @return 交互反馈
     */
    @Override
    public InteractionResult mobInteract(Player p_401345_, InteractionHand p_401405_) {
        ItemStack itemstack = p_401345_.getItemInHand(p_401405_);// 获取玩家手上的物品
        if (itemstack.is(Items.BUCKET) && !this.isBaby()) {//如果是空桶而且实体不是幼年
            p_401345_.playSound(SoundEvents.COW_MILK, 1.0F, 1.0F);//播放装奶音效
            ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, p_401345_, Items.MILK_BUCKET.getDefaultInstance());// 创建新的牛奶桶物品
            p_401345_.setItemInHand(p_401405_, itemstack1);//把奶桶物品交互在手上
            return InteractionResult.SUCCESS;//返回成功
        } else {
            return super.mobInteract(p_401345_, p_401405_);//默认返回上级交互结果
        }
    }
}
